﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace RelativePath
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                var startLocation = args[0];
                var relativePath = args[1];

                try
                {
                    // Set the starting directory
                    Directory.SetCurrentDirectory(Path.GetFullPath(startLocation));
                    Console.WriteLine("Current Directory is {0}", Directory.GetCurrentDirectory());

                    var fullPath = Path.GetFullPath(relativePath);

                    // verify relative path
                    if (File.Exists(relativePath))
                    {
                        Console.WriteLine("File Exists @ {0}. \r\n\r\nPress any key to continue...", relativePath);
                        Console.ReadKey();
                    }
                    else
                    {
                        Console.WriteLine("File Does Not Exists @ {0}. \r\n\r\nPress any key to continue...", relativePath);
                        Console.ReadKey();
                    }
                }
                catch (DirectoryNotFoundException dnfException)
                {
                    Console.WriteLine(
                        "the Start Location you supplied was not found. Please enter a vaild path and try again. \r\n\r\nPress any key to continue...");
                    Console.Read();
                }
                catch (ArgumentException argException)
                {
                    Console.WriteLine(
                        "Either the Start Location or Relative Path you supplied was not found. Please ensure that the path(s) and file name are spelled correctly and that the file exists. \r\n\r\nPress any key to continue...");
                    Console.Read();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {
                Console.WriteLine("Please supply a Starting Location and a Relative Path. \r\n\r\nPress any key to continue...");
                Console.ReadKey();
            }
        }
    }
}
